<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>驾校管理</title>
    <link href="../../layui/css/layui.css" rel="stylesheet">
    <!--<link href="./css/layuiAdmin.css" rel="stylesheet">-->
    <link href="../../static/css/style.css" rel="stylesheet">
    <script src="../../static/js/jquery.min.js"></script>
    <script src="../../layui/layui.js"></script>
    <script src="../../static/js/base.js"></script>
    <script src="../../static/js/ax.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <script src="../../static/js/avalon.js"></script>
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->
</head>

<body>

    <!--主体内容-->
    <div class="layui-fluid" ms-controller="test1">
        <div class="layui-card content-wrap">
            <!--查询-->
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form">
                    <div class="layui-form-item layui-row">
                        <div class="layui-inline layui-col-md3 layui-col-sm6">
                            <label class="layui-form-label">驾校代码：</label>
                            <div class="layui-input-block">
                                <input type="text" id="drivercode" name="code" placeholder="请输入驾校代码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3 layui-col-sm6">
                            <label class="layui-form-label">驾校名称：</label>
                            <div class="layui-input-block">
                                <input type="text" id="drivername" name="name" placeholder="请输入驾校名称" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3 layui-col-sm6">
                            <label class="layui-form-label">省份：</label>
                            <div class="layui-input-block">
                                <select lay-filter="provinceSelect" id='driverprovinceId'>
                                    <option value="">请选择</option>
                                    <option ms-attr="{value: el.code}" ms-for="($index, el) in @provlist">{{el.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3 layui-col-sm6">
                            <label class="layui-form-label">市辖：</label>
                            <div class="layui-input-block">
                                <select lay-filter="regionSelect" id='drivercityId'>
                                    <option value="">请选择</option>
                                    <option ms-attr="{value: el.code}" ms-for="($index, el) in @regionlist">{{el.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3 layui-col-sm6">
                            <label class="layui-form-label">区县：</label>
                            <div class="layui-input-block" lay-filter="selectArea">
                                <select name="sex" id="cityid" id='driverareaId'>
                                    <option value="">请选择</option>
                                    <option ms-attr="{value: el.code}" ms-for="($index, el) in @arealist">{{el.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3 layui-col-sm6">
                            <label class="layui-form-label">所属管辖：</label>
                            <div class="layui-input-block">
                                <select name="sex" id='divisionId'>
                                    <option value="">请选择</option>
                                    <option ms-attr="{value: el.id}" ms-for="($index, el) in @infolist">{{el.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline layui-col-md3 layui-col-sm6">
                            <a class="layui-btn add_btn" id="searchBtn" data-type="reload"><i class="layui-icon layui-icon-search"></i>查询</a>

                            <button ms-controller="test" class="layui-btn delete_btn" data-type="reload"><i class="layui-icon layui-icon-delete"></i>清空</button>
                        </div>
                    </div>
                </div>
            </form>

            <!--数据列表展示-->
            <div >

                    <div>
                        <button id="addschool" class="layui-btn ax-btn newsAdd_btn add_btn" lay-event="addDriver"><i class="layui-icon layui-icon-add-circle"></i>新增</button>
                        <button class="layui-btn ax-btn change_btn" lay-event="updateStudet" :click="driveedit()"><i class="layui-icon layui-icon-edit"></i>编辑</button>
                        <button class="layui-btn ax-btn delete_btn" :click="removedrive()" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</button>
                        <button class="layui-btn ax-btn add_btn" lay-event="export" :click="seeclick()">查看</button>
                    </div>



                <table class="layui-hide" id="activeListTbale" lay-filter="active"></table>
            </div>


        </div>
    </div>
    <!--主体内容-->

</body>
<script>

</script>

<script>
    var vm = avalon.define({
        $id: "test1",
        divisionId: '',
        provlist: [],
        regionlist: [],
        arealist: [],
        infolist: [],
        pro_city_are: {},
        provinceid:'',
        cityid:'',
        // 编辑驾校详情
        driveedit: function () {
            var checkStatus = table.checkStatus('testReload'), data = checkStatus.data;
            if (data.length == 0) {
                layer.alert("至少选择一条数据");
                return;
            }
            if (data.length > 1) {
                layer.alert("最多选择一条数据");
                return;
            }
            top.layer.open({
                title: "驾校修改",
                type: 2,
                fixed: true, //不固定
                maxmin: true,
                area: ['80%', '80%'],
                content: './aos/gather/driveeidt.html?id=' + data[0].id
            });
        },
        // 删除驾校
        removedrive: function () {
            var checkStatus = table.checkStatus('testReload'), data = checkStatus.data;
            if (data.length == 0) {
                layer.alert("至少选择一条数据");
                return;
            }
            if (data.length > 1) {
                layer.alert("最多选择一条数据");
                return;
            }

            layer.confirm('真的删除该驾校吗', function (index) {
                //修改
                ax.post({
                    url: schoolWebUrl + '/api/gather/delete',
                    contentType: "application/x-www-form-urlencoded",
                    data: { "id": data[0].id },
                    success: function (data) {
                        if (data.code == 0) {
                                layer.msg(data.message);
                                table.reload('testReload');
                                form.render('select');//重新加载select
                            } else {
                                layer.confirm(data.message);
                            }
                    },
                });

            });
        },
        // 获取省份
        getprovlist: function () {
            ax.post({
                url:schoolWebUrl +  '/api/captcha/getRegionProvince',
                contentType: "application/x-www-form-urlencoded",
                data: '',
                success: function (r) {
                    vm.provinceid = r.data[0].code;
                    vm.provlist = r.data;
                    vm.getRegionlist();
                },
            });
        },
        // 获取市
        getRegionlist: function () {
            ax.post({
                url: schoolWebUrl + '/api/captcha/getRegionCode',
                contentType: "application/x-www-form-urlencoded",
                data: { "code": vm.provinceid },
                success: function (r) {
                    vm.cityid = r.data[0].code;
                    vm.regionlist = r.data;
                    vm.getArealist();
                    vm.getinfolist();

                },
            });
        },
        // 获取区县
        getArealist: function () {
            // $('#areaId').empty();
            ax.post({
                url: schoolWebUrl + '/api/captcha/getRegionCode',
                contentType: "application/x-www-form-urlencoded",
                data: { "code": vm.cityid },
                success: function (r) {
                    vm.arealist = (r.data);
                    setTimeout(function () {
                        form.render('select');
                    },200)

                },
            });
        },
        //获取该市下面的车管所
        getinfolist: function () {
            ax.post({
                url: schoolWebUrl + '/api/division/info',
                contentType: "application/x-www-form-urlencoded",
                data: { "cityId": vm.cityid },
                success: function (r) {
                    vm.infolist = (r.data);
                    setTimeout(function () {
                        form.render('select');
                    },200)
                },
            });
        },
        seeclick:function () {
            var checkStatus = table.checkStatus('testReload'), data = checkStatus.data;
            top.layer.open({
                title: "驾校修改",
                type: 2,
                fixed: true, //不固定
                maxmin: true,
                area: ['90%', '80%'],
                content: './aos/gather/driveinfo.html?id=' + data[0].id
            });
        }

    })
    vm.$watch('onReady', function () {
        //获取省市区
        vm.getprovlist();
        // vm.getGather();

    })

    var table;
    var form
    layui.use(['element', 'table', 'form', 'laydate', 'layer', 'upload'], function () {
        table = layui.table;
        form = layui.form,
            laydate = layui.laydate,
            layer = layui.layer,
            upload = layui.upload,
            $ = layui.jquery,
            element = layui.element;

        //省改变
        form.on('select(provinceSelect)', function (data) {
            vm.provinceid = data.value;
            vm.getRegionlist();
        });
        // 市改变
        form.on('select(regionSelect)', function (data) {
            vm.cityid = data.value;
            vm.getArealist();
            vm.getinfolist();
        });


        //常规用法
        laydate.render({
            elem: '#activeTime'
            , range: true
        });

        var tableIns = ax.VTable({
            elem: '#activeListTbale',
            url: schoolWebUrl + '/api/gather/list',
            id: 'testReload',
            toolbar: '#toolbarDemo',
            title: '学员数据列表',
            page: true,
            cols: [[{
                type: 'checkbox',
                fixed: 'left'
            }, {
                width: 50,
                title: '序号',
                fixed: 'left',
                type:"numbers"
            }, {
                field: 'region',
                title: '区域',
                minWidth: 140,
                fixed: 'left'
            }, {
                field: 'typeName',
                title: '驾校类型',
                minWidth: 60,
                fixed: 'left'
            }, {
                field: 'code',
                width: 180,
                title: '驾校代码',
            }, {
                field: 'name',
                width: 200,
                title: '驾校名称',
            }, {
                field: 'address',
                width: 200,
                title: '驾校地址',
            }, {
                field: 'divisionName',
                width: 120,
                title: '所属管辖',
                templet: '#stateTpl'
            }, {
                field: 'contacts',
                width: 100,
                title: '驾校联系人'
            }, {
                field: 'mobile',
                width: 120,
                title: '联系电话',
            }, {
                field: 'username',
                width: 100,
                title: '创建人',
            }, {
                field: 'created',
                width: 180,
                title: '创建时间',
            }]]

        });

        var $ = layui.$, student = {
            reload: function () {
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: {
                    }
                });
            },
            reloadClean: function () {
                form.render('select');//重新加载select
                table.reload('testReload');
            }
        };

        var $ = layui.$, registers = {

            reload: function () {
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        divisionId: $('#divisionId').val(),
                        name: $("#drivername").val(),
                        code: $('#drivercode').val(),
                        provinceId: $('#driverprovinceId').val(),
                        cityId: $('#drivercityId').val(),
                        areaId: $('#driverareaId').val(),
                    }
                });
            }
        };
        $('#searchBtn').on('click', function () {
            var type = $(this).data('type');
            registers[type] ? registers[type].call(this) : '';
        });


        //新增报名点
        $('#addschool').on('click', function () {
            top.layer.open({
                title: "新增驾校",
                type: 2,
                fixed: true, //不固定
                maxmin: true,
                area: ['80%', '80%'],
                content: './aos/gather/driveadd.html'
            });
        });



        $('#show').on('click', function () {
            var type = $(this).data('type');//获取reload
            student[type] ? student[type].call(this) : '';
        });





    });



</script>

</html>